<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>title</title>
  <!--按顺序引入-->
  <script src="https://cdn.staticfile.org/react/16.8.4/umd/react.development.js"></script>
  <script src="https://cdn.staticfile.org/react-dom/16.8.4/umd/react-dom.development.js"></script>
  <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
  <script src="../js/babel.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/prop-types/15.8.1/prop-types.js"></script>
  <style>
    body {
      width: 95vw;
      height: 80vh;
      background-color: #2b2b2b;
      color: wheat;
    }
  </style>
</head>
<body>
<div id="app"></div>

<script type="text/babel">
  class Demo extends React.Component {
    state = {username: '', psw: ''}

    render() {
      return (
        <form onSubmit={this.submit}>
          <label>用户名:
            <input onChange={(event)=>this.saveData('username', event.target.value)} type="text" name="username"/>
          </label>
          <label>密码:
            <input onChange={(event)=>this.saveData('psw', event.target.value)} type="text" name="password"/>
          </label>
          <button>登录</button>
        </form>
      )
    }

    saveData = (prop, value) => {
      this.setState({[prop]: value})
    }

    submit= (e) => {
      // 阻止默认事件
      e.preventDefault()
    }
  }

  ReactDOM.render(<Demo />, document.getElementById('app'))
</script>
</body>
</html>
